<?php

require_once 'cf/init.inc';
require_once 'cf/page.inc';
require_once 'cf/ceo.inc';

define('RECS_ON_PAGE', 8);


$sitemap = new SiteMap('http://seadesign.ru');

Page::useFriendlyURLs(Page::USE_HIERARCICAL_FRIENDLY_URLS);

$pages = Pages::toHierarchyTree();

foreach ($pages as $page)
{
	$sitemap->addUrl($page['link'],null,'daily','1.0');
	if ($page['link'] == '/portfolio')
	{
		$count = query2var('SELECT COUNT(*) FROM projects');
		$pages = ceil($count/RECS_ON_PAGE);
		for($i=2; $i<=$pages; ++$i) {
			$sitemap->addUrl("/portfolio/page-$i",null,'daily');
		}
	}
}


$cats = query2arrays("SELECT id, IFNULL(code,id) AS code FROM project_categories ORDER BY sort_order");
foreach ($cats as $cat)
{
	$sitemap->addUrl('/portfolio/'.$cat['code'],null,'daily');
	
	$count = query2var('SELECT COUNT(*) FROM projects WHERE category='.$cat['id']);
	$pages = ceil($count/RECS_ON_PAGE);

	for($i=2; $i<=$pages; ++$i) {
		$sitemap->addUrl('/portfolio/'.$cat['code']."/page-$i",null,'daily');
	}

	$projects = query2vector('SELECT IFNULL(projects.code,projects.id) as id FROM projects WHERE category='.$cat['id']);
	
	foreach ($projects as $project)
	{
		$sitemap->addUrl('/portfolio/'.$cat['code'].'/'.$project,null,'weekly');
	}
}

?>

